//
//  TabBarViewController.m
//  BiLiBiLixiangmu01
//
//  Created by apple on 16/5/6.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "TabBarViewController.h"

#import "DiscoveryViewController.h"
#import "FirstpageViewController.h"
#import "FocusViewController.h"
#import "MineViewController.h"


@interface TabBarViewController ()

@end

@implementation TabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    //添加所有的子控制器
    [self setupAllChildViewControllers];
    //设置底部的titletabBar按钮内容
    [self setupAllTitleButtons];

}
//由于不用自定义tabBar所以我们的项目会比较简单一点

#pragma mark-----3.(抽取代码)全局统一设置tabBar上面不被渲染的文字
+(void)load{
    //获取全局的tabBarItem,要调用appearance方法,它表示全局
    UITabBarItem  *item = [UITabBarItem appearance];
    //3.1设置选中状态的文字
    NSMutableDictionary *attr  = [NSMutableDictionary dictionary];
    attr[NSForegroundColorAttributeName] = [UIColor blackColor];
    [item setTitleTextAttributes:attr forState:UIControlStateSelected];
    //3.2设置正常状态的文字
    NSMutableDictionary *attrnor = [NSMutableDictionary dictionary];
    attrnor[NSFontAttributeName] = [UIFont systemFontOfSize:15];
    [item setTitleTextAttributes:attrnor forState:UIControlStateNormal];
}


#pragma mark----2.设置底部的titletabBar按钮内容

//设置底部的titletabBar按钮内容
-(void)setupAllTitleButtons{
    //0.首页
    UINavigationController *nav = self.childViewControllers[0];
    nav.tabBarItem.title = @"首页";
    //(正常图片)
    nav.tabBarItem.image = [UIImage imageNamed:@"tabBar_firstpage_icon"];
    //(选中图片)
    nav.tabBarItem.selectedImage = [UIImage imageNameWithOriginal:@"tabBar_firstpage_click_icon"];

    //1.关注
    UINavigationController *nav1 = self.childViewControllers[1];
    nav1.tabBarItem.title = @"关注";
    //(正常图片)
    nav1.tabBarItem.image = [UIImage imageNamed:@"tabBar_focus_icon"];
    //(选中图片)
    nav1.tabBarItem.selectedImage = [UIImage imageNameWithOriginal:@"tabBar_focus_click_icon"];


   //2.发现
    UINavigationController *nav2 = self.childViewControllers[2];
    nav2.tabBarItem.title = @"发现";
    //(正常图片)
    nav2.tabBarItem.image = [UIImage imageNamed:@"tabBar_discovery_icon"];
    //(选中图片)
    nav2.tabBarItem.selectedImage = [UIImage imageNameWithOriginal:@"tabBar_discovery_click_icon"];


    //3.我的
    UINavigationController *nav3 = self.childViewControllers[3];
    nav3.tabBarItem.title = @"我的";
    //(正常图片)
    nav3.tabBarItem.image = [UIImage imageNamed:@"tabBar_me_icon"];
    //(选中图片)
    nav3.tabBarItem.selectedImage = [UIImage imageNameWithOriginal:@"tabBar_me_click_icon"];



}

#pragma mark ---------1.添加所有的子控制器
-(void)setupAllChildViewControllers{
    //首页控制器
    FirstpageViewController *firstpageVc = [[FirstpageViewController alloc]init];
    UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:firstpageVc];
    [self addChildViewController:nav];
    //关注控制器
    FocusViewController *focusVc = [[FocusViewController alloc]init];
    UINavigationController *nav1 = [[UINavigationController alloc]initWithRootViewController:focusVc];
    [self addChildViewController:nav1];
    //发现控制器
    DiscoveryViewController *discoveryVc = [[DiscoveryViewController alloc]init];
    UINavigationController *nav2 = [[UINavigationController alloc]initWithRootViewController:discoveryVc];
    [self addChildViewController:nav2];
    
    //我的控制器
    MineViewController *mineVc = [[MineViewController alloc]init];
    UINavigationController *nav3 = [[UINavigationController alloc]initWithRootViewController:mineVc];
    [self addChildViewController:nav3];
}
@end
